package com.课上案例练习.线程.创建线程;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * 创建线程
 * 使用Callable
 * 使用lammba表达式，是因为Callable接口就只有一个方法
 */
public class Test3 {
    public static void main(String[] args) throws ExecutionException, InterruptedException {
        Thread11 thread11 = new Thread11();
        FutureTask<String> futureTask = new FutureTask<String>(thread11);
        Thread thread = new Thread(futureTask);
        thread.start();
        String s = futureTask.get();
        System.out.println(s);
    }

    private static void demo1() throws InterruptedException, ExecutionException {
        FutureTask<String> futureTask = new FutureTask(() -> {
            return "线程启动";
        });
        Thread thread = new Thread(futureTask);
        thread.start();
        String s = futureTask.get();
        System.out.println(s);
    }
}
class Thread11 implements Callable{

    @Override
    public String call() throws Exception {
        for (int i = 0; i <10 ; i++) {
            System.out.println(i);
        }
        return "启动线程";
    }
}